import dayjs from 'dayjs';

export default function(app) {
    app.directive("format-time", {
        mounted(el, bindings) {
            // bindings.value获取的就是参数
            let formatString = bindings.value;

            // 如果没有传参数 就使用默认的
            if(!formatString) {
                formatString = 'YYYY-MM-DD HH:mm:ss'
            }

            // 格式化时间戳
            const textContent = el.textContent;
            let timestamp = parseInt(textContent);

            if (textContent.length === 10) {
                timestamp = timestamp * 1000
            }

            // el.textContent = dayjs(timestamp).format("YYYY-MM-DD HH:mm:ss");
            el.textContent = dayjs(timestamp).format(formatString);




            // console.log(textContent);
        }
    })
}